package org.example.arraylist01;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * ArrayList遍历(迭代)
 * 1.迭代器遍历
 * 2.特有遍历方式:索引遍历
 * 3.增强for
 */
public class ArrayListDemo03 {
    public static void main(String[] args) {

        //method01();
        //method02();
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        for (String s : al) {
            System.out.println(s);
        }
    }

    private static void method02() {
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        for (int i = 0; i < al.size(); i++) {
            System.out.println(al.get(i));
        }
    }

    private static void method01() {
        ArrayList<String> al = new ArrayList<>();
        al.add("abc");
        al.add("love");
        al.add("ghk");
        for (Iterator<String> iterator = al.iterator();iterator.hasNext();
        ){System.out.println(iterator.next());
        }

    }
}
